//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Diagnostics.Contracts;
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet
{
    
    class InternalNumberFormat: IOfficeXmlSerializable
    {
        public InternalNumberFormat()
        {

        }
        public override string ToString()
        {
            return Code;
        }
        public InternalNumberFormat(string formatCode, int id)
        {
            code = formatCode;
            Id = id;

        }
	
        public override bool Equals(object obj)
        {
            InternalNumberFormat f = obj as InternalNumberFormat;
            if (f != null)
                return code == f.code && f.id == id;
            return false;
        }
        public override int GetHashCode()
        {
            int result = id;
            if (code != null)
                result += code.GetHashCode();
            return result;
        }
        private string code;

        public string Code
        {
            get { return code; }
            //\\set { code = value; }
        }
	
       //\\ public string Code { get { return format.Code; } }
        private int id;

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        internal InternalNumberFormat Clone()
        {
            return MemberwiseClone() as InternalNumberFormat;
        }


        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read("numFmt"))
            {
                code  = c.GetString ("formatCode");
                Id = c.GetInteger("numFmtId");
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("numFmt"))
            {
                Contract.Assert(Id >= 0);
                c.SetInteger("numFmtId", Id);
                c.SetString("formatCode", Code);
            }
        }

        #endregion

        
    }
}
